package com.focus.wecenter.pojo;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.Date;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @description  文章
 * 
 * @author		Lv Jing
 * @date		2018-1-8 17:22:34
 */
@Entity
@Table(name = "article", schema = "wecenter")
@DynamicUpdate
@DynamicInsert
public class Article implements Serializable {
	private static final long serialVersionUID = 1L;

	private Integer id;  	
	/**标题*/
	private String title;
	/**文章内容*/
	private String content;
	/**评论数量*/
	private Integer commentCount;
	/**添加时间*/
	private Date createTime;
	/**用户编号*/
	private User createUser;
	/**评论*/
	private Set<ArticleComment> comments = new HashSet<>(0);
	/**所属话题*/
	private Set<Topic> involvedTopics = new HashSet<>(0);

    @JoinTable(name = "topic_article", joinColumns = {@JoinColumn(name = "article_id")}, inverseJoinColumns = {@JoinColumn(name = "topic_id")})
    @ManyToMany
    public Set<Topic> getInvolvedTopics() {
        return involvedTopics;
    }
    public void setInvolvedTopics(Set<Topic> involvedTopics) {
        this.involvedTopics = involvedTopics;
    }
    @OneToMany
    @JoinColumn(name = "article_id")
    @OrderBy("createTime asc")
    public Set<ArticleComment> getComments() {
        return comments;
    }
    public void setComments(Set<ArticleComment> comments) {
        this.comments = comments;
    }
    @JoinColumn(name = "user_id")
	@ManyToOne
    public User getCreateUser() {
        return createUser;
    }
    public void setCreateUser(User createUser) {
        this.createUser = createUser;
    }
    @Id
    @Column(name = "ARTICLE_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Basic
    @Column(name = "TITLE")
	public String getTitle() {
		return this.title;
	}
	public void setTitle(String title) {
		this.title = title;
	}	
	@Basic
    @Column(name = "CONTENT")
	public String getContent() {
		return this.content;
	}
	public void setContent(String content) {
		this.content = content;
	}
    @Basic
    @Column(name = "comments")
    public Integer getCommentCount() {
        return commentCount;
    }
    public void setCommentCount(Integer commentCount) {
        this.commentCount = commentCount;
    }
    @Basic
    @Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

    @Override
    public boolean equals(Object o) {
        if (this == o) {return true;}
        if (o == null || getClass() != o.getClass()) {return false;}
        Article article = (Article) o;
        return Objects.equals(id, article.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}